﻿namespace XDevelopHelper.LogHelper
{
    /// <summary>
    /// 输出代理
    /// </summary>
    public static class Log
    {
        public delegate void OutDelegate(string toPrint);

        // 输出代理事件
        public static event OutDelegate OutEvent;

        // 输出级别，低于这个数字的logLevel才会被输出
        public static int LogDetailedLevel = 5;

        /// <summary>
        /// 输出函数
        /// 如果logLevel小于当前的LogDetailedLevel，将toPrint作为参数传入OutEvent中执行
        /// </summary>
        /// <param name="toPrint">要输出的字符串</param>
        /// <param name="logLevel">输出级别，低于Log.LogDetailedLevel的才能被输出</param>
        public static void Out(string toPrint, int logLevel)
        {
            if (OutEvent != null && logLevel <= LogDetailedLevel)
            {
                OutEvent.Invoke(toPrint);
            }
        }

        /// <summary>
        /// 输出函数
        /// 保证一定能输出
        /// </summary>
        /// <param name="toPrint"></param>
        public static void Out(string toPrint)
        {
            // 保证可见
            Log.Out(toPrint, LogDetailedLevel - 1);
        }

        /// <summary>
        /// 输出函数
        /// 如果logLevel小于当前的LogDetailedLevel，将toPrint作为参数传入OutEvent中执行
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="format"></param>
        /// <param name="Params"></param>
        public static void Out(int logLevel, string format, params object[] Params)
        {
            string toPrint = string.Format(format, Params);
            Log.Out(toPrint, logLevel);
        }


        /// <summary>
        /// 输出函数
        /// 如果logLevel小于当前的LogDetailedLevel，将toPrint作为参数传入OutEvent中执行
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="format"></param>
        /// <param name="Params"></param>
        public static void Out(string format, params object[] Params)
        {
            string toPrint = string.Format(format, Params);
            Log.Out(toPrint, LogDetailedLevel - 1);
        }
    }
}
